package com.jerry.security.validate.sms;

import com.jerry.security.config.SecurityConfigProperties;
import com.jerry.security.validate.ValidateCode;
import com.jerry.security.validate.ValidateCodeGenerator;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private SecurityConfigProperties securityConfigProperties;

    @Override
    public ValidateCode generate(HttpServletRequest request) {
        String code = RandomStringUtils.randomNumeric(securityConfigProperties.getSmsCode().getLength());
        return new SmsCode(code, securityConfigProperties.getSmsCode().getExpireIn());
    }

}
